cssmatcher: Handle case of empty widget path
authorBenjamin Otte <otte@redhat.com>
Mon, 30 Apr 2012 19:28:57 +0000 (21:28 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 1 May 2012 01:13:02 +0000 (03:13 +0200)
This is tested by the stylecontext test, but doesn't appear in practice.

gtk/gtkcssmatcher.c
gtk/gtkcssmatcherprivate.h
gtk/gtkcssprovider.c
gtk/gtkstylecontext.c

index e67c9eff719ecccca281945c7a4c3a97fa3606e5..c656ef48e7e2b60e15eaea45f643d511f45c77b9 100644 (file)
@@ -187,16 +187,21 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
   gtk_css_matcher_widget_path_has_position,
 };
 
-void
+gboolean
 _gtk_css_matcher_init (GtkCssMatcher       *matcher,
                        const GtkWidgetPath *path,
                        GtkStateFlags        state)
 {
+  if (gtk_widget_path_length (path) == 0)
+    return FALSE;
+
   matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH;
   matcher->path.path = path;
   matcher->path.state_flags = state;
   matcher->path.index = gtk_widget_path_length (path) - 1;
   matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);
+
+  return TRUE;
 }
 
 /* GTK_CSS_MATCHER_WIDGET_ANY */
index 121e286ce3dee398a9f96567cf3fdabc2d693e7a..1b4c632ff9aac9171cafe925532602a8a8716b1d 100644 (file)
@@ -72,9 +72,9 @@ union _GtkCssMatcher {
   GtkCssMatcherSuperset     superset;
 };
 
-void              _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
+gboolean          _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
                                                    const GtkWidgetPath    *path,
-                                                   GtkStateFlags           state);
+                                                   GtkStateFlags           state) G_GNUC_WARN_UNUSED_RESULT;
 void              _gtk_css_matcher_any_init       (GtkCssMatcher          *matcher);
 void              _gtk_css_matcher_superset_init  (GtkCssMatcher          *matcher,
                                                    const GtkCssMatcher    *subset,
index 7241a1d6d501787abf1d2325d6ae7babedcdc40e..128edc3af19b5afbc5d9fa80206dfafa21f6b102 100644 (file)
@@ -1485,25 +1485,26 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
   props = gtk_style_properties_new ();
 
   css_provider_dump_symbolic_colors (css_provider, props);
-  _gtk_css_matcher_init (&matcher, path, 0);
-
-  for (i = 0; i < priv->rulesets->len; i++)
+  if (_gtk_css_matcher_init (&matcher, path, 0))
     {
-      GtkCssRuleset *ruleset;
+      for (i = 0; i < priv->rulesets->len; i++)
+        {
+          GtkCssRuleset *ruleset;
 
-      ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
+          ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
 
-      if (ruleset->styles == NULL)
-        continue;
+          if (ruleset->styles == NULL)
+            continue;
 
-      if (!gtk_css_ruleset_matches (ruleset, &matcher))
-        continue;
+          if (!gtk_css_ruleset_matches (ruleset, &matcher))
+            continue;
 
-      for (j = 0; j < ruleset->n_styles; j++)
-       _gtk_style_properties_set_property_by_property (props,
-                                                       GTK_CSS_STYLE_PROPERTY (ruleset->styles[i].property),
-                                                       _gtk_css_selector_get_state_flags (ruleset->selector),
-                                                       ruleset->styles[i].value);
+          for (j = 0; j < ruleset->n_styles; j++)
+            _gtk_style_properties_set_property_by_property (props,
+                                                            GTK_CSS_STYLE_PROPERTY (ruleset->styles[i].property),
+                                                            _gtk_css_selector_get_state_flags (ruleset->selector),
+                                                            ruleset->styles[i].value);
+        }
     }
 
   return props;
@@ -1524,10 +1525,12 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
   gchar *prop_name;
   gint i;
 
+  if (!_gtk_css_matcher_init (&matcher, path, state))
+    return FALSE;
+
   prop_name = g_strdup_printf ("-%s-%s",
                                g_type_name (pspec->owner_type),
                                pspec->name);
-  _gtk_css_matcher_init (&matcher, path, state);
 
   for (i = priv->rulesets->len - 1; i >= 0; i--)
     {
index f18c8aba354ca5ae4d306585e372b6f00f405cc6..5fd398eaa982853f5ef432db56f24b77379f2077 100644 (file)
@@ -905,12 +905,12 @@ build_properties (GtkStyleContext *context,
 
   priv = context->priv;
 
-  _gtk_css_matcher_init (&matcher, path, state);
   lookup = _gtk_css_lookup_new ();
 
-  _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
-                                      &matcher,
-                                      lookup);
+  if (_gtk_css_matcher_init (&matcher, path, state))
+    _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+                                        &matcher,
+                                        lookup);
 
   style_data->store = _gtk_css_computed_values_new ();
   _gtk_css_lookup_resolve (lookup, context, style_data->store);
@@ -3061,10 +3061,12 @@ _gtk_style_context_validate (GtkStyleContext *context,
           GtkCssMatcher matcher;
 
           path = create_query_path (context);
-          _gtk_css_matcher_init (&matcher, path, priv->info->state_flags);
+          if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
+            priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+                                                                             &matcher);
+          else
+            priv->relevant_changes = 0;
 
-          priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
-                                                                           &matcher);
           priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
 
           gtk_widget_path_unref (path);